<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- <div id="box" class="contTxt">
        <span>1234</span>
        --689
    </div> -->
    <script>
        //虚拟dom本质为一个js对象
        const vDom = {
            type: 'div',
            props: {
                id: 'box',
                className: "contTxt"
            },
            children: [{
                    type: "span",
                    props: {},
                    children: ['123456']

                },
                '--689'
            ]
        }
        //将虚拟dom转换为真是dom
        function vDomTobDom({
            type,
            props,
            children
        }) {
            //1、根据type创建标签
            const rDom = document.createElement(type)
            //2、给真实dom添加属性
            Object.keys(props).forEach(item => {
                rDom[item] = props[item]
            })
            //3、添加子元素
            children.forEach(item => {
                if (typeof item === 'string') {
                    const text = document.createTextNode(item)
                    rDom.appendChild(text)
                } else {
                    rDom.appendChild(vDomTobDom(item))
                }
            })
            return rDom
        }
        document.body.appendChild(vDomTobDom(vDom))
    </script>
</body>

</html>